package com.example.indenture.company.dao;

import com.example.indenture.common.vo.Search;
import com.example.indenture.race.entity.Race;
import com.example.indenture.company.entity.Company;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
@Mapper
public interface CompanyDao {
    @Insert("insert into company(company_name, create_date, update_time,email,password,phone,des,url) " +
            "values(#{companyName}, #{createDate}, #{updateTime},#{email}, #{password}, #{phone}, #{des},#{url})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insertCompany(Company company);

    @Update("update company set company_name = #{companyName}, password=#{password}, " +
            "update_time = #{updateTime},email=#{email},phone=#{phone},url=#{url},des=#{des} where id = #{id}")
    void updateCompany(Company company);

    @Select("select * from company where id=#{id}")
    Company selectCompanyById(int id);

    @Select("select * from company where company_name=#{companyName}")
    Company selectCompanyByName(String companyName );

    @Select("SELECT * FROM company WHERE company_name=#{companyName} AND password=#{password}")
    Company login(String companyName,String password);

    @Select("<script>"
            + "select * from company "
            + "<where> "
            + "<if test='keyword != \"\" and keyword != null'>"
            + " and (company_name like '%${keyword}%') "
            + "</if>"
            + "</where>"
            + "<choose>"
            + "<when test='sort != \"\" and sort != null'>"
            + " Order by ${sort} ${direction}"
            + "</when>"
            + "<otherwise>"
            + " Order by id desc"
            + "</otherwise>"
            + "</choose>"
            + "</script>")
    List<Company> getCompanyBySearch(Search search);

    @Update("update company set url=#{url} where id=#{id}")
    void  updateCompanyUrl(int id,String url);

    @Select("select * from company where company_name=#{companyName}")
    Company getPasswordByName(String companyName);


}
